package com.yunxin.core.infra.persistence.repository.channel;

import com.yunxin.core.domain.model.channel.ChannelAdvanceChargeRecord;
import com.yunxin.core.domain.model.channel.ChannelAdvanceChargeRecordRepository;
import com.yunxin.core.infra.persistence.converter.ChannelConvertor;
import com.yunxin.core.infra.persistence.entity.channel.ChannelAdvanceChargeRecordDO;
import com.yunxin.core.infra.persistence.mapper.channel.ChannelAdvanceChargeRecordExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-12-16
 */
@Repository
@RequiredArgsConstructor
public class ChannelAdvanceChargeRecordRepositoryImpl implements ChannelAdvanceChargeRecordRepository {

    private final ChannelConvertor channelConvertor;

    private final ChannelAdvanceChargeRecordExtendMapper channelAdvanceChargeRecordExtendMapper;

    @Override
    public boolean saveChannelAdvanceChargeRecord(ChannelAdvanceChargeRecord channelAdvanceChargeRecord) {
        ChannelAdvanceChargeRecordDO channelAdvanceChargeRecordDO = channelConvertor.formChannelAdvanceChargeRecord(channelAdvanceChargeRecord);
        int result = channelAdvanceChargeRecordExtendMapper.insertSelective(channelAdvanceChargeRecordDO);
        return result > 0;
    }

    @Override
    public boolean updateChannelAdvanceChargeRecord(ChannelAdvanceChargeRecord channelAdvanceChargeRecord) {
        ChannelAdvanceChargeRecordDO channelAdvanceChargeRecordDO = channelConvertor.formChannelAdvanceChargeRecord(channelAdvanceChargeRecord);
        int result = channelAdvanceChargeRecordExtendMapper.updateByPrimaryKeySelective(channelAdvanceChargeRecordDO);
        return result > 0;
    }

    @Override
    public ChannelAdvanceChargeRecord getChannelAdvanceChargeRecordById(Long id) {
        ChannelAdvanceChargeRecordDO channelAdvanceChargeRecordDO = channelAdvanceChargeRecordExtendMapper.selectByPrimaryKey(id);
        return channelConvertor.toChannelAdvanceChargeRecord(channelAdvanceChargeRecordDO);
    }
}
